<?php
/**
* alltosun.com  订单方面接口
* ============================================================================
* 版权所有 (C) 2009-2015 北京互动阳光科技有限公司，并保留所有权利。
* 网站地址: http://www.alltosun.com
* ----------------------------------------------------------------------------
* 许可声明: 这是一个开源程序，未经许可不得将本软件的整体或任何部分用于商业用途及再发布。
* ============================================================================
* $Author: 张元昊 (zhangyh@alltosun.com) $
* $Date: 2015-11-30 17:24:44 $
* $Id$
*/

class Action
{

    private $per_page = 20;

    private $token = '';
    private $user_id = 0;
    private $user_info = array();
    private $api_stat_id = 0;

    public function __construct()
    {
        $this->token = an_request('token');

        if ($this->token) {
            $user_info = user_helper::get_user_info_by_token($this->token);
            if ($user_info && $user_info['status'] == 1) {
                $this->user_id = $user_info['id'];
                $this->user_info = $user_info;
            }
        }

    }

    /**
     * 获取终端库存
     * http://192.168.2.246:8080/workspace/myWorkspace.action?projectId=1#66
     */
    public function get_cup_data()
    {
        $box_num   = an_request('box_num');
        $arr_scale = an_request('scale', '', 'request', 0);
        $store_id  = an_request('store_id');

        $params['box_num']  = $box_num;
        $params['scale']  = $arr_scale;
        $params['store_id']  = $store_id;

        $api_stat_id = api_helper::check_sign($params, 1);
        if (!$this->user_id) {
            api_helper::return_data(1, '请先登录');
        }

        $data = _widget('cup')->get_app_dealer_cup_num($store_id, $box_num, json_decode($arr_scale, true));
        if ($data) {
            api_helper::return_data(0, 'success', $data);
        } else {
            api_helper::return_data(1, '暂无数据');
        }
    }

    /**
     * 获取杯型数据(终端) 终端没有前三次2倍超发概念
     * http://192.168.2.246:8080/workspace/myWorkspace.action?projectId=1#67
     */
    public function get_app_store_cup_data()
    {
        $box_num   = an_request('box_num');
        $arr_scale = an_request('scale', '', 'request', 0);
        $store_id  = an_request('store_id');

        $params['box_num']  = $box_num;
        $params['scale']  = $arr_scale;
        $params['store_id']  = $store_id;

        $api_stat_id = api_helper::check_sign($params, 1);
        if (!$this->user_id) {
            api_helper::return_data(1, '请先登录');
        }

        $data = _widget('cup')->get_app_store_cup_num($store_id, $box_num, json_decode($arr_scale, true));
        if ($data) {
            api_helper::return_data(0, 'success', $data);
        } else {
            api_helper::return_data(1, '暂无数据');
        }
    }

    /**
     * 获取经销商杯子库存
     */
    public function get_app_dealer_stock()
    {
        $store_id  = an_request('store_id');
        $params['store_id']  = $store_id;

        api_helper::check_sign($params, 1);
        if (!$this->user_id) {
            api_helper::return_data(1, '请先登录');
        }

        $data =  _widget('cup')->get_app_dealer_stock($store_id);
        if ($data) {
            api_helper::return_data(0, 'success', $data);
        } else {
            api_helper::return_data(1, '暂无数据');
        }
    }
}